Skip to content

cppcheck.cpp: Check for JSON error when parsing addon .json files#2374

Merged
versat merged 6 commits into
cppcheck-opensource:masterfrom
versat:addons_detect_json_errors
Nov 20, 2019
Merged

cppcheck.cpp: Check for JSON error when parsing addon .json files#2374
versat merged 6 commits into
cppcheck-opensource:masterfrom
versat:addons_detect_json_errors

Conversation

@versat

@versat versat commented Nov 18, 2019

Copy link
Copy Markdown
Collaborator

This fixes that errors in JSON files given via --addon=*.json are
silently ignored and maybe only a part of the JSON file is used.
Now the error message which picojson can return is checked and a
corresponding error message is returned again by getAddonInfo().

Comment thread lib/cppcheck.cpp
const std::string &failedToGetAddonInfo = addonInfo.getAddonInfo(addon, mSettings.exename);
if (!failedToGetAddonInfo.empty()) {
reportOut(failedToGetAddonInfo);
mExitCode = 1;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danmar I guess this is not correct. It looks like this variable is meant for analysis errors. But in this case, it is an error in an input file. Is there a better way to set the exit code that also does not need --error-exitcode= beeing set?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me this feels ok. It's serious if this does not work.

@jubnzv

jubnzv commented Nov 18, 2019

Copy link
Copy Markdown
Contributor

For information, it's already implemented in #2367 here (see also: tests and GUI integration). So we'll get errors handing after merging this changes, in next release, I think.

@versat

versat commented Nov 18, 2019

Copy link
Copy Markdown
Collaborator Author

For information, it's already implemented in #2367 here (see also: tests and GUI integration). So we'll get errors handing after merging this changes, in next release, I think.

Yes throwAddonError() is exactly what I would need here.
@danmar How shall we proceed? Change this PR to only print the error but behave like before and wait until after the release for throwAddonError()?

@jubnzv

jubnzv commented Nov 18, 2019

Copy link
Copy Markdown
Contributor

@versat I think it's better to merge it for now and replace it later. It is good if the user will have error messages in current release.

@versat versat force-pushed the addons_detect_json_errors branch from 653c7f3 to 98e9c6b Compare November 19, 2019 07:34
@versat

versat commented Nov 19, 2019

Copy link
Copy Markdown
Collaborator Author

I have added the possibility to check the naming of constants to naming.py. Without this enhancement, the addon does not make so much sense. Constants often are named different than normal variables, and Cppcheck is no exception here.

I had to loosen the naming validation rules in naming.json since there are some names that are hard or impossible to fix. For example, a constructor of a class that is inside another class seems to be not marked as a constructor. This results in false positives. So I allowed functions to begin with upper letters for now.
Another problem I do not yet know how to best solve are argument names beginning with underscore _. Code is like void f(int _var) { int var = _var}. So I allowed variable names to begin with an underscore for now.

I have fixed naming violations in CLI/LIB/GUI so Travis is happy now.
The plan is to make the naming rules more strict again and fix it in further PRs.
I did not want to create such a big PR, but fixing one thing resulted in other things that need fixing and so on :(
@danmar What do you think?

This fixes that errors in JSON files given via `--addon=*.json` are
silently ignored and maybe only a part of the JSON file is used.
Now the error message which picojson can return is checked and a
corresponding error message is returned again by getAddonInfo().
@versat versat force-pushed the addons_detect_json_errors branch from df75a1a to c4ed95a Compare November 20, 2019 06:59
@danmar

danmar commented Nov 20, 2019

Copy link
Copy Markdown
Collaborator

The plan is to make the naming rules more strict again and fix it in further PRs.
I did not want to create such a big PR, but fixing one thing resulted in other things that need fixing and so on :(

sounds like a good approach.

@versat versat merged commit c990d10 into cppcheck-opensource:master Nov 20, 2019
@versat versat deleted the addons_detect_json_errors branch November 20, 2019 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants